/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/


#ifndef MK_RTMP_PARAM_H
#define MK_RTMP_PARAM_H
#include "MkRtmpUtil.h"
#include "MkAmf/MkAmf.h"

class MkApi CMkRtmpParam
{
public:
    CMkRtmpParam();
    virtual ~CMkRtmpParam();

    Uint32 ParseRtmpMessage(const Uint8* pBuf, Uint32 nLen, Uint32& nUsed);
    Uint32 AddMapTransaction(Uint32& Id, const MkString& Cmd);
    virtual Uint32 OnCommandRequest(const MkString& Command, const MkVector<MkAmfObject>& VecObj);
    virtual Uint32 OnAudio(const Uint8* pBuf, Uint32 nLen, Uint32 TimeStamp);
    virtual Uint32 OnVideo(const Uint8* pBuf, Uint32 nLen, Uint32 TimeStamp);
    virtual Uint32 OnMetaData(const MkVector<MkAmfObject>& VecObj);
    virtual Uint32 OnConnectResult(BOOL bSuccess);
    virtual Uint32 OnCreateStreamResult(BOOL bSuccess);
    virtual Uint32 OnPublishResult(const MkString Level, const MkString& Description, const MkString& Code);
private:
    Uint32 ParseRtmpControlEvent(const Uint8* pBegin, const Uint8* pEnd);
    Uint32 ParseRtmpAmf0Body(const Uint8* pBegin, const Uint8* pEnd);
    Uint32 ParseResponse(const MkVector<MkAmfObject>& VecObj, BOOL bSuccess);
    Uint32 ParseRtmpAmf3Body(const Uint8* pBegin, const Uint8* pEnd);
private:
    Uint32 OnCommandResponse(const MkString& Command, const MkVector<MkAmfObject>& VecObj, BOOL bSuccess);
protected:
    Uint8*                  m_pPacketBuffer;
    Uint32                  m_PacketMaxLen;
    Uint32                  m_nPacketOffset;

    Uint8*                  m_pRecvBuffer;
    Uint32                  m_RecvMaxLen;
    Uint32                  m_nRecvOffset;
    Uint32                  m_InChunkSize;
    Uint32                  m_OutChunkSize;
    Uint32                  m_SendRecvSize;
    Uint32                  m_nServerBw;
    Uint32                  m_nClientBw;
    Uint8                   m_nClientBw2;
    Uint32                  m_TransactionId;
    Uint32                  m_TimeStamp;
    MkRtmpPauseState        m_PauseState;
    MkMap<Uint32, MkString> m_MapTransactionCmd;
};

#endif





